home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / GDK / Node.as < prev    next >
Text File  |  2006-11-29  |  10KB  |  397 lines

  1. class GDK.Node
  2. {
  3.    static var created = 0;
  4.    var className = "Node";
  5.    var uniqueID = -1;
  6.    var x = 0;
  7.    var y = 0;
  8.    var z = 0;
  9.    var isDisplayNode = false;
  10.    var angle = 0;
  11.    var renderable = true;
  12.    static var COLLISION_OK = 1;
  13.    static var COLLISION_CANCEL = 2;
  14.    static var COLLISION_SKIP_EVENT = 3;
  15.    static var collisionID = 0;
  16.    var classID = 0;
  17.    var collisionMask = 0;
  18.    var collisionOverlap = false;
  19.    var inScene = false;
  20.    var keepInScene = false;
  21.    var rogueNode = false;
  22.    var affectChildren = true;
  23.    var allowChildren = true;
  24.    var hasChildren = false;
  25.    var stopCol = false;
  26.    var editor_isItem = false;
  27.    var editor_tool = "CreateObject";
  28.    var editor_description = "Description for item";
  29.    var editor_name = "Generic Object";
  30.    var editor_args_names = [];
  31.    var editor_args_values = [];
  32.    var editor_args_types = [];
  33.    var editor_args_options = [];
  34.    var editor_args_descriptions = [];
  35.    var editor_args_mode = [];
  36.    var editor_args_component = [];
  37.    var editor_commands = [];
  38.    var editor_canChangeAsset = true;
  39.    var editor_canChangeLayer = true;
  40.    var editor_canChangeFrame = true;
  41.    var editor_nullDefaultsOnSave = true;
  42.    var editor_canRotate = false;
  43.    var editor_canScale = false;
  44.    function Node()
  45.    {
  46.       this.uniqueID = ++GDK.Node.created;
  47.       new GDK.EventSubscriber(this);
  48.       this.setRenderable(this.renderable);
  49.       this.setAffectChildren(this.affectChildren);
  50.       if(this.onAddToWorld)
  51.       {
  52.          this.addEvent("addToWorld",this.onAddToWorld,this);
  53.       }
  54.       if(this.onRemoveFromWorld)
  55.       {
  56.          this.addEvent("removeFromWorld",this.onRemoveFromWorld,this);
  57.       }
  58.       if(this.onAddToScene)
  59.       {
  60.          this.addEvent("addToScene",this.onAddToScene,this);
  61.       }
  62.       if(this.onRemoveFromScene)
  63.       {
  64.          this.addEvent("removeFromScene",this.onRemoveFromScene,this);
  65.       }
  66.       if(this.onAddDisplay)
  67.       {
  68.          this.addEvent("addDisplay",this.onAddDisplay,this);
  69.       }
  70.       if(this.onRemoveDisplay)
  71.       {
  72.          this.addEvent("removeDisplay",this.onRemoveDisplay,this);
  73.       }
  74.    }
  75.    function setAngle(angle)
  76.    {
  77.       this.angle = angle;
  78.       if(this.target)
  79.       {
  80.          this.target._rotation = angle;
  81.       }
  82.       this.sendEvent("rotate",angle);
  83.    }
  84.    function addToScene()
  85.    {
  86.       if(this.inScene)
  87.       {
  88.          return undefined;
  89.       }
  90.       this.world.addActiveObject(this);
  91.       this.inScene = true;
  92.       this.addDisplay();
  93.       this.sendEvent("addToScene");
  94.       if(this.children)
  95.       {
  96.          var _loc2_ = this.children.length;
  97.          while((_loc2_ = _loc2_ - 1) > -1)
  98.          {
  99.             this.children[_loc2_].addToScene();
  100.          }
  101.       }
  102.    }
  103.    function removeFromScene()
  104.    {
  105.       if(!this.inScene || this.keepInScene)
  106.       {
  107.          return undefined;
  108.       }
  109.       this.removeDisplay();
  110.       this.inScene = false;
  111.       this.world.removeActiveObject(this);
  112.       this.sendEvent("removeFromScene");
  113.       if(this.children)
  114.       {
  115.          var _loc2_ = this.children.length;
  116.          while((_loc2_ = _loc2_ - 1) > -1)
  117.          {
  118.             this.children[_loc2_].removeFromScene();
  119.          }
  120.       }
  121.    }
  122.    function setAffectChildren(b)
  123.    {
  124.       if(this.affectChildren == b)
  125.       {
  126.          return undefined;
  127.       }
  128.       if(this.affectChildren = b)
  129.       {
  130.          if(this.children)
  131.          {
  132.             this.onBeginParent();
  133.          }
  134.       }
  135.       else if(this.children)
  136.       {
  137.          this.onEndParent();
  138.       }
  139.    }
  140.    function addChild(child, isolated)
  141.    {
  142.       if(!this.allowChildren || child.parent == this)
  143.       {
  144.          return false;
  145.       }
  146.       child.parent.removeChild(child);
  147.       child.parent = this;
  148.       if(this.world && this.world != child.world)
  149.       {
  150.          this.world.addObject(child,true);
  151.       }
  152.       if(this.children == undefined)
  153.       {
  154.          if(this.affectChildren)
  155.          {
  156.             this.positionChanged = this.pv_positionChanged;
  157.          }
  158.          this.onBeginParent();
  159.          this.hasChildren = true;
  160.          this.children = [child];
  161.       }
  162.       else
  163.       {
  164.          this.children.push(child);
  165.       }
  166.       if(this.inScene && !isolated)
  167.       {
  168.          child.addToScene();
  169.       }
  170.       this.onAddChild(child);
  171.       return true;
  172.    }
  173.    function removeChild(child)
  174.    {
  175.       if(!this.children || child.parent != this)
  176.       {
  177.          return undefined;
  178.       }
  179.       var _loc2_ = this.children.length;
  180.       while((_loc2_ = _loc2_ - 1) > -1)
  181.       {
  182.          if(this.children[_loc2_] == child)
  183.          {
  184.             this.children.splice(_loc2_,1);
  185.             break;
  186.          }
  187.       }
  188.       child.parent = undefined;
  189.       if(!this.children.length)
  190.       {
  191.          delete this.positionChanged;
  192.          this.onEndParent();
  193.          this.hasChildren = false;
  194.          delete this.children;
  195.       }
  196.    }
  197.    function addToWorld(newWorld)
  198.    {
  199.       newWorld.addObject(this);
  200.    }
  201.    function removeFromWorld()
  202.    {
  203.       this.world.removeObject(this);
  204.    }
  205.    function detachFromParent()
  206.    {
  207.       this.parent.removeChild(this);
  208.    }
  209.    function becomeChildTo(parent)
  210.    {
  211.       parent.addChild(this);
  212.    }
  213.    function requestDisplaySpace()
  214.    {
  215.       if(!this.displayNode)
  216.       {
  217.          var _loc2_ = this.parent;
  218.          while(_loc2_)
  219.          {
  220.             if(_loc2_.isDisplayNode)
  221.             {
  222.                break;
  223.             }
  224.             _loc2_ = _loc2_.parent;
  225.          }
  226.          this.displayNode = !_loc2_ ? this.world.target : _loc2_.target;
  227.       }
  228.       var _loc3_ = undefined;
  229.       if(this.assetID != null)
  230.       {
  231.          _loc3_ = this.displayNode.attachMovie(this.assetID,"mc" + this.uniqueID,2130690045 - this.uniqueID);
  232.       }
  233.       else
  234.       {
  235.          _loc3_ = this.displayNode.createEmptyMovieClip("mc" + this.uniqueID,2130690045 - this.uniqueID);
  236.       }
  237.       return _loc3_;
  238.    }
  239.    function addDisplay()
  240.    {
  241.       if(!this.renderable || this.target)
  242.       {
  243.          return undefined;
  244.       }
  245.       this.queueForDisplay();
  246.       this.target = this.requestDisplaySpace();
  247.       this.sendEvent("addDisplay");
  248.    }
  249.    function removeDisplay()
  250.    {
  251.       this.sendEvent("removeDisplay");
  252.       this.target.swapDepths(0);
  253.       this.target.removeMovieClip();
  254.       delete this.target;
  255.    }
  256.    function setAssetID(newAssetID)
  257.    {
  258.       if(this.assetID == newAssetID)
  259.       {
  260.          return undefined;
  261.       }
  262.       if(this.inScene)
  263.       {
  264.          this.removeDisplay();
  265.       }
  266.       this.assetID = newAssetID;
  267.       if(this.inScene)
  268.       {
  269.          this.addDisplay();
  270.       }
  271.    }
  272.    function queueForDisplay()
  273.    {
  274.       if(this.renderable)
  275.       {
  276.          this.world.queueForDisplay(this);
  277.       }
  278.    }
  279.    function setRenderable(b)
  280.    {
  281.       if(b)
  282.       {
  283.          delete this.queueForDisplay;
  284.          if(this.inScene)
  285.          {
  286.             this.addDisplay();
  287.          }
  288.       }
  289.       else if(this.inScene)
  290.       {
  291.          this.removeDisplay();
  292.       }
  293.    }
  294.    function checkCollisionList(objects, flag, options, maxCol)
  295.    {
  296.       if(maxCol == null)
  297.       {
  298.          maxCol = 256;
  299.       }
  300.       if(flag == null)
  301.       {
  302.          return undefined;
  303.       }
  304.       this.stopCol = false;
  305.       var _loc3_ = 0;
  306.       var _loc6_ = undefined;
  307.       var _loc4_ = objects.length;
  308.       GDK.Node.collisionID = GDK.Node.collisionID + 1;
  309.       var _loc2_ = undefined;
  310.       while(!this.stopCol && (_loc4_ = _loc4_ - 1) > -1)
  311.       {
  312.          if(!((_loc2_ = objects[_loc4_]) != this && GDK.Node.collisionID != _loc2_.lastCollisionID && (flag & _loc2_.classID) > 0))
  313.          {
  314.             continue;
  315.          }
  316.          _loc2_.lastCollisionID = GDK.Node.collisionID;
  317.          if(_loc6_ = this.checkCollision(_loc2_))
  318.          {
  319.             _loc3_ = _loc3_ + 1;
  320.          }
  321.          switch(_loc6_)
  322.          {
  323.             case 1:
  324.                if(this.onCollision(objects[_loc4_],options) == GDK.Node.COLLISION_CANCEL)
  325.                {
  326.                   return _loc3_;
  327.                }
  328.                break;
  329.             case 2:
  330.                return _loc3_;
  331.          }
  332.       }
  333.       return _loc3_;
  334.    }
  335.    function checkCollision(obj)
  336.    {
  337.       return false;
  338.    }
  339.    function moveTo(x, y, z)
  340.    {
  341.       this.moveBy(x - this.x,y - this.y,z - this.z);
  342.    }
  343.    function moveBy(x, y, z)
  344.    {
  345.       if(x || y || z)
  346.       {
  347.          this.x += x;
  348.          this.y += y;
  349.          this.z += z;
  350.          this.positionChanged(x,y,z);
  351.       }
  352.    }
  353.    function moveToGlobally(x, y, z)
  354.    {
  355.    }
  356.    function positionChanged(xShift, yShift, zShift)
  357.    {
  358.       this.onMove(xShift,yShift,zShift);
  359.       this.queueForDisplay();
  360.    }
  361.    function pv_positionChanged(xShift, yShift, zShift)
  362.    {
  363.       this.onMove(xShift,yShift,zShift);
  364.       var _loc2_ = this.children.length;
  365.       while((_loc2_ = _loc2_ - 1) > -1)
  366.       {
  367.          this.children[_loc2_].moveBy(xShift,yShift,zShift);
  368.       }
  369.       this.queueForDisplay();
  370.    }
  371.    function setDisplay()
  372.    {
  373.       this.target._x = this.x;
  374.       this.target._y = this.y;
  375.    }
  376.    function getUpdates()
  377.    {
  378.       this.world.addEvent("update",function(elapsed)
  379.       {
  380.          this.update(elapsed);
  381.       }
  382.       ,this);
  383.    }
  384.    function cancelUpdates()
  385.    {
  386.       this.world.removeEvent("update",null,this);
  387.    }
  388.    function timelineUpdate()
  389.    {
  390.       this.queueForDisplay();
  391.    }
  392.    function toString()
  393.    {
  394.       return this.className + " #" + this.uniqueID + (!this.name ? "" : "(" + this.name + ")");
  395.    }
  396. }
  397.